#ifndef QMLXMPPCLIENT_H
#define QMLXMPPCLIENT_H

#include <QObject>
#include <QtDeclarative>
#include <QStringList>
#include <QVariant>

#include <QXmppPresence.h>

//#include "MyXmppClient.h"

class QMLXmppClient : public QObject
{
    Q_OBJECT
    Q_DISABLE_COPY( QMLXmppClient )

    Q_PROPERTY( QString jidLastMsg READ getJidLastMsg NOTIFY messageReceived )

    Q_PROPERTY( bool isTyping READ getTyping NOTIFY typingChange )

    Q_PROPERTY( int Connecting READ getValueConnecting ) //const
    Q_PROPERTY( int Connected READ getValueConnected ) //const
    Q_PROPERTY( int Disconnected READ getValueDisconnected ) //const
    Q_PROPERTY( int stateConnect READ getStateConnect NOTIFY connectingChanged )

    Q_PROPERTY( QString statusText READ getStatusText NOTIFY statusTextChanged )

    Q_PROPERTY( StatusXmpp status READ getStatus NOTIFY statusChanged FINAL )

    Q_PROPERTY( QVariant subscriptionJids  READ getListSubscription NOTIFY subscriptionReceived )

    Q_PROPERTY( QString myJid READ getMyJid() NOTIFY myJidChanged )

    static QMLXmppClient* instance;

    QString jidLastMessage;
    bool flTyping;
    int m_stateConnect;
    QString m_statusText;
    QStringList m_listSubscriptions;

public:
    enum StatusXmpp {
        Online = 1,
        Chat = 2,
        Away = 3,
        XA = 4,
        DND = 5,
        Offline = 0
    };

    enum StateConnect {
        Disconnect = 0,
        Connected = 1,
        Connecting = 2
    };

    Q_ENUMS( StatusXmpp )
    explicit QMLXmppClient(QObject *parent = 0);

    static QMLXmppClient* getInstance() { return QMLXmppClient::instance; }

    void emitMsgRecv(const QString &jid ) { jidLastMessage = jid; emit messageReceived(); }
    QString getJidLastMsg() const { return jidLastMessage; }

    /* собеседник печатает/не печатает сообщение */
    bool getTyping() const { return flTyping; }
    void setTyping( QString &jid, const bool isTyping ) { flTyping = isTyping; emit typingChange(jid, isTyping); }

    /* константы определяющие соединения */
    int getValueConnecting() const { return QMLXmppClient::MYXMPP_CONNECTING; }
    int getValueConnected() const { return QMLXmppClient::MYXMPP_CONNECTED; }
    int getValueDisconnected() const { return QMLXmppClient::MYXMPP_DISCONNECTED; }
    int getStateConnect() const { return m_stateConnect; }
    void setStateConnect( const int st );

    /* статус xmpp клиента */
    StatusXmpp getStatus() const { return m_status; }
    void setStatus( QXmppPresence::Status::Type __status, const bool flNotify = true );

    /* текст статуса */
    QString getStatusText() const { return m_statusText; }
    void setStatusText( const QString &__statusText, const bool flNotify = false );

    /* */
    QVariant getListSubscription()  { return QVariant(m_listSubscriptions); }
    void setListSubscription( const QStringList &listSubscriptions ) { m_listSubscriptions = listSubscriptions; emit subscriptionReceived(); }

    /* my jid */
    QString getMyJid() const { return m_myjid; }
    void setMyJid( const QString &myJid ) { if(myJid != m_myjid) { m_myjid =myJid; emit myJidChanged(); } }

    static int MYXMPP_DISCONNECTED;
    static int MYXMPP_CONNECTED;
    static int MYXMPP_CONNECTING;

signals:
    void changeMyJid();
    void unreadMessages();
    void messageReceived();
    void typingChange( QString bareJid, bool isTyping );
    void connectingChanged();
    void statusChanged();
    void statusTextChanged();
    void subscriptionReceived();
    void myJidChanged();
    
public slots:

private:
    StatusXmpp m_status;
    QString m_myjid;
    
};

QML_DECLARE_TYPE(QMLXmppClient)

#endif // QMLXMPPCLIENT_H
